<?php
session_start();
/*
 * Session variables:
 * $_SESSION['type'] [string] = user type of the logged in user
 * $_SESSION['authorised'] [boolean] = whether or not the current user is logged in
 * $_SESSION['tutor_pass'] [string]= password of tutor who arrived
 */
if (isset($_SESSION['authorised']) && $_SESSION['authorised'] == true) {
    if (isset($_SESSION['type'])) {
        if ($_SESSION['type'] == 'administrator') {
?>
            <html xmlns="http://www.w3.org/1999/xhtml">
                <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                    <title>Tutor Arrived</title>
                    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
                    <style>
                        .nav {
                            width:210px;
                            height:auto;
                            border:thin solid #09C;

                            margin-left: 10px;
                            text-align : center;}

                        .mainline {
                            width:712px;

                            height:auto;
                            text-align : center;}
                        </style>
						<script type="text/javascript">
                        function checkPasswordMatch() {            
                            var pass1 = document.getElementById('pass1');
                            var pass2 = document.getElementById('pass2');
                            var message = document.getElementById('passwordmessage');

                            if(pass1.value == pass2.value) {
                                pass2.style.backgroundColor = "#66cc66";
                                message.style.color = "#66cc66";
                                message.innerHTML = "Passwords Match!";
                            } else {
                                pass2.style.backgroundColor = "#ff6666";
                                message.style.color = "#ff6666";
                                message.innerHTML = "Passwords Do Not Match!";
                            }
                        }
                    </script>
	
			
                    </head>

                    <center>
                        <body bgcolor="#FFFFFF">
                            <div id="wrapper">
                            <div id="header">
                                <h1></h1>
                            </div>
                            <div id="header2">
                                <h3></h3>
                            </div>

                            <div id="nav">
                             	<?php include 'admin_navigation.php';?>
                            </div>
                            <div id="mainline">
                                <h4> Tutor Arrived </h4>
                                <div id="body">                                    
                                <?php if(isset($_SESSION['tutor_pass'])== true)
								{
									echo $_SESSION['tutor_pass'];
									unset($_SESSION['tutor_pass']);
								}
								else
								{
									//nothing
								}?>
                                    <form action="admin_tutorarrivedsubmit.php" method="post">
                                        <table width="712" cellpadding="2" class="infotable" align="left">
                                               <tr align="left">
                                                <th height="42" scope="row">Tutor:</th>
                                                <td width="550">
                                                    <select name="tutor">
                                                     <?php
															include('connection.inc');
							
							                                $sql = "SELECT users.username, users.lastname || ', ' ||users.firstname AS tutor, teachers.teacher_id FROM teachers inner join users on teachers.username=users.username where teachers.is_in=false order by tutor";
							                                $result = pg_query($sql);
							                                echo "<option>Tutor's name</option>";
							                                for($i = 0; $i < pg_num_rows($result); $i++)
							                                {
							                                    $tutor = pg_fetch_result($result, $i, 'tutor');
							                                    $tutor_id = pg_fetch_result($result, $i, 'teacher_id');
							
							                                    echo "<option name=\"tutor\" value = \"$tutor_id\">$tutor</option>";
							                                }
							                                ?>
                                                    
                                                    </select>
                                            </td>
                                            </tr>
                                            <tr align="left">
                                                <th height="42" scope="row">Tutor's Password:</th>
                                                <td><input type="password" size="20" maxlength="15" id="pass1" name="pass1"/></td>
                                            </tr>
                                            <tr align="left">
                                                <th height="42" scope="row">Repeat Password:</th>
                                                <td><input type="password" size="20" maxlength="15" id="pass2" name="pass2" onkeyup="checkPasswordMatch(); return false;"/></td>
                                            </tr>
                                            <tr align="left">
                                                <td></td>
                                                <td><input type = "submit" value ="Submit" /></td>
                                            </tr>
                                        </table>
                                    </form>
                                </div>
                            </div>



                            <p align="justify"><br /></p>
                        

                        <br class="clearfloat"/>
                        <br />

                        <div id="footer">
                            <p align="center">
                                Tutorial Business Manager: info@tbms.com <br />Credits/Engineers: Aquino, Chloebelle; Dela Cruz, Roy Erwin; Maliwanag, Ranyel Bryan; Manzano, Audrey Ann; Ng, Sheila Regine<br />
                                <br />copyright 2011</p>
                        </div>
                        </div>
                    </body>
                </center>
            </html>
<?php
        } elseif ($_SESSION['type'] == 'student') {
            header('Location: student_index.php');
            exit();
        } elseif ($_SESSION['type'] == 'tutor') {
            header('Location: tutor_index.php');
            exit();
        } elseif ($_SESSION['type'] == 'parent') {
            header('Location: parent_index.php');
            exit();
        }
    }
} else {
    header('Location: index.php');
}
?>
